#!/usr/bin/python
import sys
import os



# read maps.
print "reading maps"
fin = open(sys.argv[1],"rb")
left_lines = fin.readlines()
fin.close()

fin = open(sys.argv[2],"rb")
right_lines = fin.readlines()
fin.close()
print "done"

# index left mappers.
maps = {}
for line in left_lines:
	# split
	tmp = line.split("\t")
	if tmp[2] == "*": continue
	bname = tmp[0].replace(">","").split("_")[0]
	rlen = float(tmp[0].split("=")[1])
	i = tmp[5].find("M")
	j = tmp[5].find("H")
	if j > i:	j = 0
	
	
	# Get match.
	match = float( tmp[5][j+1:i] )
	
	
	# Get percentage alignment.
	id = match / rlen
	if id >= .8:
		# Save to map.
		maps[bname] = [tmp,None]
			
# Index right mappers.
for line in right_lines:
	# split
	tmp = line.split("\t")
	if tmp[2] == "*": continue
	bname = tmp[0].replace(">","").split("_")[0]
	rlen = float(tmp[0].split("=")[1])
	i = tmp[5].find("M")
	j = tmp[5].find("H")
	if j > i:	j = 0
	
	# Get match.
	match = float( tmp[5][j+1:i] )
	
	# Get percentage alignment.
	id = match / rlen
	if id >= .8:
		# Save to map.
		if bname in maps:
			maps[bname][1] = tmp
		else:
			maps[bname] = [None,tmp]
	
# See which ones have pairs.
for bname in maps:
	if maps[bname][0] != None and maps[bname][1] == None:
		print bname
	elif maps[bname][1] != None and maps[bname][0] == None:
		print bname
